﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Entity.DomainModels.HealthEducation;
using VOL.SmartMecial.Infrastructure;
using VOL.SmartMecial.IServices.HealthEducation;

namespace VOL.SmartMecial.Services.HealthEducation
{
    /// <summary>
    /// 广播内容接口实现
    /// </summary>
    public class BroadCastService:IBroadCastService
    {
        private readonly IBaseRepository<BroadCastModel> _broadCastRepo;

        public BroadCastService(IBaseRepository<BroadCastModel> broadCastRepo)
        {
            _broadCastRepo = broadCastRepo;
        }

        /// <summary>
        /// 添加广播内容
        /// </summary>
        /// <param name="broadCastModel"></param>
        /// <returns></returns>
        public async Task<int> AddBroadCast(BroadCastModel broadCastModel)
        {
            return await _broadCastRepo.AddAsync(broadCastModel);
        }

        /// <summary>
        /// 删除广播内容
        /// </summary>
        /// <param name="id">广播ID</param>
        /// <returns></returns>
        public async Task<int> DeleteBroadCast(int id)
        {
            var entity = await _broadCastRepo.FindAsync(id);
            if (entity == null)
                return 0;
            
            return await _broadCastRepo.Remove(entity);
        }

        /// <summary>
        /// 获取所有广播内容
        /// </summary>
        /// <returns>广播内容列表</returns>
        public async Task<List<BroadCastModel>> GetBroadCastModels()
        {
            return await Task.FromResult(_broadCastRepo.GetAll().ToList());
        }

        /// <summary>
        /// 更新广播内容
        /// </summary>
        /// <param name="broadCastModel">广播模型</param>
        /// <returns></returns>
        public async Task<int> UpdateBroadCast(BroadCastModel broadCastModel)
        {
            return await _broadCastRepo.UpdateAsync(broadCastModel);
        }
    }
}
